<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page import="com.smarthome.web.property.utils.UserHolder"  %>
<!DOCTYPE html>
<html>
	<head>
		<title>短信记录</title>
		<jsp:include page="../../views/layout/inc.jsp"></jsp:include>
		<script type="text/javascript">
			var dataGrid;
			$(function() {
				dataGrid = $('#dataGrid').datagrid({
					url : '/messageRecordController/dataGrid',
					fit : true,
					fitColumns : true,
					border : false,
					pagination : true,
					idField : 'id',
					pageSize : 10,
					pageList : [ 10, 20, 30, 40, 50 ],
					sortName : 'gmtCreate',
					sortOrder : 'desc',
					checkOnSelect : false,
					selectOnCheck : false,
					singleSelect : true,
					nowrap : false,
					frozenColumns : [ [ {
						field : 'id',
						title : '编号',
						width : 100,
						hidden : true,
						checkbox : false
					}, {
						field : 'residenceName',
						title : '小区名字',
						width : 100
					}, {
						field : 'typeName',
						title : '短信类型',
						width : 120
					} ] ],
					columns : [ [ {
						field : 'accountName',
						title : '收件人',
						hidden : true,
						width : 80
					}, {
						field : 'mobile',
						title : '收件手机',
						width : 100
					}, {
						field : 'content',
						title : '短信内容',
						width : 270
					}, {
						field : 'status',
						title : '状态',
						width : 150,
						formatter:function(val,rec){ 
							if (val == 1) {
								return '成功';
							} else if(val == 2) {
								return '失败';
							} else if(val == 3) {
								return '处理中';
							} else if(val == 4) {
								return '发送中';
							}
						}
					}, {
						field : 'gmtCreate',
						title : '创建时间',
						width : 150,
						sortable : true,
						formatter:function(val,rec){ 
							 var unixTimestamp = new Date(val);  
		                     return unixTimestamp.format("yyyy-MM-dd hh:mm:ss");  
						}
					}, {
						field : 'gmtModify',
						title : '更新时间',
						width : 150,
						sortable : true,
						formatter:function(val,rec){ 
							 var unixTimestamp = new Date(val);  
		                     return unixTimestamp.format("yyyy-MM-dd hh:mm:ss");  
						}
					} ] ],
					toolbar : '#toolbar',
					onLoadSuccess : function() {
						$('#searchForm table').show();
						parent.$.messager.progress('close');
						$(this).datagrid('tooltip');
					},
					onRowContextMenu : function(e, rowIndex, rowData) {
						e.preventDefault();
						$(this).datagrid('unselectAll').datagrid('uncheckAll');
						$(this).datagrid('selectRow', rowIndex);
					}
				});
				
				
				
			 $('#residenceId').combobox({
					url : '/residenceController/combobox'
				}); 
				
				/* $.post('/residenceController/combobox',{},function(data){
					$('#residenceId').combobox({'data':data});
				},'json'); */
			});
			
			function searchFun() {
				dataGrid.datagrid('load', $.serializeObject($('#searchForm')));
			}
	
			function addFun() {
				parent.$.modalDialog({
					title : '短信发送',
					width : 600,
					height : 300,
					href : '/messageRecordController/tosend',
					buttons : [ {
						text : '确认发送',
						handler : function() {
							parent.$.modalDialog.openner_dataGrid = dataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
							var f = parent.$.modalDialog.handler.find('#form');
							f.submit();
						}
					} ]
				});
			}

			function cleanFun() {
				$('#searchForm input').val('');
				dataGrid.datagrid('load', {});
			}
		</script>
	</head>
	<body>
		<div class="easyui-layout" data-options="fit : true,border : false">
			<div data-options="region:'north',title:'查询条件',border:false" style="height: 90px; overflow: hidden;">
				<form id="searchForm">
					<table class="table table-hover table-condensed" style="display: none;">
						<tr>
							<th>发送状态</th>
							<td>
								<select id="status" name="status" class="easyui-combobox" data-options="width:140,height:29,editable:false,panelHeight:'auto',icons:[{iconCls:'icon-clear',handler: function(e){$(e.data.target).combobox('setValue','');}}]">
									<option value="1">成功</option>
									<option value="2">失败</option>
									<option value="3">处理中</option>
									<option value="4">发送中</option>
								</select>
							</td>
						</tr>
							<%if(UserHolder.isSuperResidence()){ %>
							<tr>
							<th>小区名字</th>
							<td>
								<input id="residenceId" name="residenceId"   data-options=" width:140,height:29,icons:[{iconCls:'icon-clear',handler: function(e){$(e.data.target).combobox('setValue','');}}]"/>
								
								</td>
						</tr>
							<%} %>
					</table>
				</form>
			</div>
			<div data-options="region:'center',border:false">
				<table id="dataGrid"></table>
			</div>
			<div id="toolbar" style="display: none;">
				<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="searchFun();">提交查询</a>
				<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true" onclick="cleanFun();">重置查询</a>
				<a onclick="addFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'">短息发送</a>
			</div>
		</div>
	</body>
</html>